package cn.springdate;

import cn.bdqn.dao.SysRoleDao;
import cn.bdqn.dao.SysUserDao;
import cn.bdqn.entity.SysRole;
import cn.bdqn.entity.SysUser;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.annotation.Rollback;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashSet;

//声明这个类是spring的测试类  告诉这个类spring里面所有的东西都可以使用
@RunWith(SpringJUnit4ClassRunner.class)
//加载配置文件    classpath:根目录
@ContextConfiguration(locations = "classpath:applicationContext.xml")
public class ManyToMany {

    @Autowired
    private SysUserDao sysUserDao;

    @Autowired
    private SysRoleDao sysRoleDao;


    @Test
    @Transactional
    @Rollback(false)
    public void add(){
        SysRole sysRole = new SysRole();
        sysRole.setRoleMemo("超级管理员");

        SysUser sysUser = new SysUser();
        sysUser.setUserName("admin");
        HashSet<SysUser> sysUsers = new HashSet<SysUser>();
        sysUsers.add(sysUser);

        sysRole.setUsers(sysUsers);
        sysRoleDao.save(sysRole);



    }


}
